package com.forlove.app.qselect.answer.widght;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.forlove.app.R;


/**
 * 答题的答案的item
 * Created by yjl on 2017/10/12.
 */

public class AnswerItemView extends RelativeLayout {
    private Context mContext;
    private View mRootView;
    private ImageView answer_back_view;
    //    private LottieAnimationView lottieAnimationView;
    private TextView answerTitle;
    private AppCompatImageView circleSelectImage;
    private boolean isSelected = false;
    private AppCompatImageView image_hide_name;
    private ImageView image_is_selected;
    private ObjectAnimator objectAnimator;

    public AnswerItemView(Context context) {
        super(context);
        initView(context);
    }

    public AnswerItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public AnswerItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context mContext) {
        this.mContext = mContext;
        LayoutInflater inflater = (LayoutInflater) this.mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mRootView = inflater.inflate(R.layout.item_answer, this);
//        lottieAnimationView = (LottieAnimationView) mRootView.findViewById(R.id.lottie_answer);
//        lottieAnimationView.playAnimation();

        answerTitle = (TextView) (TextView) mRootView.findViewById(R.id.text_answer_name);
        circleSelectImage = (AppCompatImageView) mRootView.findViewById(R.id.image_select);
        answer_back_view = (ImageView) mRootView.findViewById(R.id.answer_back_view);
        image_hide_name = (AppCompatImageView) mRootView.findViewById(R.id.image_hide_name);
        image_is_selected = (ImageView) mRootView.findViewById(R.id.image_is_selected);

    }

    public void setAnswerTitle(String answerTitle) {
        this.answerTitle.setText(answerTitle);
    }

    public void selectCircleFriend(boolean selected) {
        isSelected = selected;
//        if (selected) {
//            circleSelectImage.setVisibility(VISIBLE);
//        } else {
//            circleSelectImage.setVisibility(INVISIBLE);
//        }
    }

    public boolean getFriendCircled() {
//        if (circleSelectImage.isShown()) {
//            return true;
//        }
        return isSelected;
    }

    public void showBackView(int color, float precent) {
        answer_back_view.setVisibility(VISIBLE);
        answer_back_view.setBackgroundColor(color);
        answer_back_view.setAlpha(0.6f);
        objectAnimator = ObjectAnimator.ofFloat(answer_back_view,
                "scaleX", 0, precent);
        answer_back_view.setPivotX(0);
        objectAnimator.setDuration(300);
        objectAnimator.start();
    }

    public void hideBackView() {
        if (objectAnimator != null) {
            objectAnimator.cancel();
            objectAnimator = null;
        }
        answer_back_view.setVisibility(INVISIBLE);
    }


    public void hideFriendName(int Color) {
        image_hide_name.setVisibility(VISIBLE);
        answerTitle.setVisibility(INVISIBLE);
        answer_back_view.setVisibility(VISIBLE);
        answer_back_view.setBackgroundColor(Color);
        answer_back_view.setAlpha(0.6f);
    }

    public void showFriendName() {
        image_hide_name.setVisibility(INVISIBLE);
        answerTitle.setVisibility(VISIBLE);
        answer_back_view.setVisibility(INVISIBLE);
    }

    public void showCrownView() {
        image_is_selected.setVisibility(VISIBLE);
    }
}
